fix: wrap top-level array params in anyOf to also accept JSON-encoded strings#261
Open
cheafon wants to merge 1 commit into
Open
fix: wrap top-level array params in anyOf to also accept JSON-encoded strings#261cheafon wants to merge 1 commit into
cheafon wants to merge 1 commit into
Conversation
… strings
Some MCP clients (e.g. Claude Code, Cursor) double-serialize top-level
array parameters, sending them as a JSON string (e.g. "[{...}]") instead
of an actual array. This caused `notion-create-pages` to fail with:
Invalid input: expected array, received string
The existing `withStringFallback` already handles this for object-typed
params by wrapping them in `anyOf: [schema, { type: 'string' }]`.
This commit applies the same treatment to array-typed params.
At runtime, `deserializeParams()` in proxy.ts already correctly converts
the JSON-encoded string back to an array, so no runtime changes are needed.
Fixes: makenotion#176
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When calling
notion-create-pagesfrom Claude Code (or Cursor), thepagesarray parameter arrives as a JSON-encoded string instead of an actual array,
causing validation to fail:
This is a known MCP client behavior where top-level array parameters get
double-serialized (
JSON.stringify'd) before being sent.Root Cause
withStringFallback()inparser.tsalready handles this for objectparameters by wrapping them in
anyOf: [schema, { type: 'string' }]—allowing both the native type and a JSON-encoded string. However, this
treatment was missing for array parameters.
The runtime fix (
deserializeParams()inproxy.ts) already correctlyconverts
"[...]"strings back to arrays — so only the schema validationneeded to be updated.
Fix
Apply the same
anyOf: [array, string]wrapping to array-typed parametersin
withStringFallback(). This is consistent with the existing objecthandling and resolves the schema validation error.
Testing
parser.test.tscovering an array request bodyparameter (mirrors the
notion-create-pages/pagesscenario)parser-multipart.test.tsexpectations to reflect thenew
anyOfstructure for array propertiesFixes #176